package com.qf.shiro.user.service.impl;

import com.qf.shiro.user.entity.User;
import com.qf.shiro.user.mapper.UserDao;
import com.qf.shiro.user.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.shiro.utils.SaltUtils;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ljc
 * @since 2023-02-08
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserService {

    @Autowired
    UserDao userDao;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void regist(User user) {

    //注册时随机盐字符串
        String salt = SaltUtils.getSalt(8);

        user.setSalt(salt);

        Md5Hash md5Hash = new Md5Hash(user.getPassword(), salt, 1024);

        String sercetPwd = md5Hash.toHex();

        user.setPassword(sercetPwd);

        save(user);


    }

    @Override
    public List<String> getPerms(User user) {
        List<String> list = userDao.getPerms(user);
        return list;
    }

    @Override
    public List<String> getRoles(User user) {
        List<String> list =  userDao.getRoles(user);

        return list ;
    }


}
